package com.aps.apspda.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.view.View;

import com.aps.apspda.R;
import com.aps.apspda.activity.LoggingTCMActivity;
import com.aps.apspda.callback.StringCommonCallBack;
import com.aps.apspda.dialog.GeneralFragmentDialog;
import com.aps.apspda.dialog.TCMFragmentDialog;
import com.aps.apspda.entity.InputDataEntity;
import com.aps.apspda.entity.InputDatasEntity;
import com.aps.apspda.entity.MessageEntity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author anyang
 * @date 2017/9/11
 * @desc
 */

public class LoggingTCMListAdapter extends BaseQuickAdapter<InputDatasEntity.InputObjects, BaseViewHolder> {
    private FragmentManager fragmentManager;
    private String  eqpID;
    private String eqpType;
  //  private List<InputDataEntity.InputObject> inputList = new ArrayList<>();
  private InputDataEntity inputDataEntity; //add by bunny
    public LoggingTCMListAdapter(@Nullable List<InputDatasEntity.InputObjects> data,String eqpID,String eqpType) {
        super(R.layout.adapter_tcm_list, data);
        this.eqpID=eqpID;
        this.eqpType=eqpType;
    }

    public void setFragmentManager(FragmentManager fragmentManager) {
        this.fragmentManager = fragmentManager;
    }
    @Override
    protected void convert(BaseViewHolder helper, final InputDatasEntity.InputObjects item) {
        helper.setText(R.id.btnContent, item.getDATANAME());

        helper.getView(R.id.btnContent).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(eqpType.contains("ASM")){
                    inputDataEntity=item.getINPUTDATAS();
                    Intent intent = new Intent(mContext, LoggingTCMActivity.class);
                    intent.putExtra("eqpID",eqpID);
                    intent.putExtra("dataName", item.getDATANAME());
                    intent.putExtra("datacName", item.getDATACNNAME());
                    intent.putExtra("inputList",  inputDataEntity);
                    intent.putExtra("subeqpID",eqpID);
                    mContext.startActivity(intent);
                }
                else{
                    final TCMFragmentDialog dialog = new TCMFragmentDialog();
                    dialog.setData(eqpID,item.getDATANAME());
                    dialog.setCallBackAndWhere(new StringCommonCallBack() {
                        @Override
                        public void onCallback(String str) {
                            //消息询问是否可以继续  如果成功跳转，失败，弹报警界面
                            inputDataEntity=item.getINPUTDATAS();
                            Intent intent = new Intent(mContext, LoggingTCMActivity.class);
                            intent.putExtra("eqpID",eqpID);
                            intent.putExtra("dataName", item.getDATANAME());
                            intent.putExtra("inputList",  inputDataEntity);
                            intent.putExtra("subeqpID",str);
                            mContext.startActivity(intent);
                            dialog.dismiss();
                        }
                    }, 1);
                    dialog.show(fragmentManager, "eqp_start_dialog");
            }}
        });
   }
}
